#include "AVLTree_Head.h"
#include<iostream>
#include<cmath>
using namespace std;

int K = 0, count = 0;
template<class comparable>
void function(AVLTreeNode<comparable>* AVLnode, int number1, int number2) {
	if (AVLnode == nullptr) {
		return;
	}
	if (AVLnode->key >= number1 && AVLnode->key <= number2) {
		count++;
		function(AVLnode->left, number1, number2);
		cout << AVLnode->key;
		K++;
		function(AVLnode->right, number1, number2);
	}
	else if (AVLnode->key < number1) {
		count++;
		function(AVLnode->right, number1, number2);
	}
	else if (AVLnode->key > number2) {
		function(AVLnode->left, number1, number2);
		count++;
	}
}

int main() {
	freopen("data.in", "r", stdin);
	int x, n, k1, k2,i;
	cin >> n;
	AVLTree<int>* AVL_Tree;
	AVL_Tree = new AVLTree<int>();
	for (i = 0; i <n ; i++) {
		cin >> x;
		(* AVL_Tree).Insert(x);
	}
	cin >> k1;
	cin >> k2;
	function(( * AVL_Tree).root, k1, k2);
	cout << "Number of nodes visited:" << count << endl;
	cout << "N:" << n << endl;
	cout << "K:" << K << endl;
	cout << "K+log(N)=" << K + log(n) << endl;
	return 0;
}